<?php
namespace app\admin\controller;
use app\admin\controller\AdminController;
/**
 * 积分管理
 */
class IntegralController extends AdminController {
    /**
     * 当前模块参数
     */
    protected function _infoModule(){
        return array(
            'menu' => array(
                    array(
                        'name' => '积分列表',
                        'url' => url('index'),
                        'icon' => 'bars',
                    ),
                    array(
                        'name' => '操作积分',
                        'url' => url('setting'),
                        'icon' => 'plus',
                    ),
                ),
            );
    }

	/**
     * 列表
     */
    public function index(){
        //筛选条件
        $where = array();
        $keyword = request('request.keyword','');
        if(!empty($keyword)){
            $where[] = "B.username = :keyword OR B.user_id = :keyword";
            $where[':keyword'] = $keyword;
        }
    	//管理目录导航
    	$this->adminCrumb[] = array('url'=>url('index'),'name'=>'积分管理');
        $list = target('forum/Integral')->page(20)->loadList($where);
        $this->pager = target('forum/Integral')->pager;
        //URL参数
        $pageMaps = array();
        $pageMaps['keyword'] = $keyword;
        $this->assign('list', $list);
        $this->assign('page', $this->getPageShow($pageMaps));
        $this->assign('pageMaps',$pageMaps);
        $this->adminDisplay();
    }

    /**
     * 操作
     */
    public function setting(){
        if(!IS_POST){
            //管理目录导航
            $this->adminCrumb[] = array('url'=>url('index'),'name'=>'积分管理');
            $this->adminCrumb[] = array('url'=>url('setting'),'name'=>'积分设置');
            $this->adminDisplay('info');
        }else{
            $data = request('post.');
            if(target('forum/Integral')->settingInt($data['username'],$data['num'],$data['type'],$data['remarks'])){
                $this->success('积分操作成功！',url('index'));
            }else{
                $msg = target('forum/Integral')->getError();
                if(empty($msg)){
                    $this->error('积分操作失败');
                }else{
                    $this->error($msg);
                }
                
            }

        }
    }

    /**
     * 删除
     */
    public function del(){
        $IntegralId = request('post.data');
        if(empty($IntegralId)){
            $this->error('参数不能为空！');
        }
        //删除积分操作
        if(target('forum/Integral')->delData($IntegralId)){
            $this->success('积分删除成功！');
        }else{
            $msg = target('forum/Integral')->getError();
            if(empty($msg)){
                $this->error('积分删除失败！');
            }else{
                $this->error($msg);
            }
        }
    }
}

